local xiandang = fk.CreateSkill{
  name = "hanqing__xiandang",
}

Fk:loadTranslationTable{
  ["hanqing__xiandang"] = "献党",
  [":hanqing__xiandang"] = "其他角色对你使用的牌不计入次数。你受到伤害后，可以将一张牌与此技能交给伤害来源。",

  ["#hanqing__xiandang-invoke"] = "献党：是否将一张牌和此技能交给 %dest？",

  ["$hanqing__xiandang1"] = "今献上党十七城，再续三晋旧谊。",
  ["$hanqing__xiandang2"] = "宁吞山东草，不嗅关西馐，吾意已决！",
}

xiandang:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(xiandang.name) and
      data.from and data.from ~= player and not data.from.dead and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local card = room:askToCards(player, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      skill_name = xiandang.name,
      prompt = "#hanqing__xiandang-invoke::"..data.from.id,
      cancelable = true,
    })
    if #card > 0 then
      event:setCostData(self, {tos = {data.from}, cards = card})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:moveCardTo(event:getCostData(self).cards, Card.PlayerHand, data.from, fk.ReasonGive, xiandang.name, nil, false, player)
    if not player.dead then
      room:handleAddLoseSkills(player, "-hanqing__xiandang")
    end
    if not data.from.dead then
      room:handleAddLoseSkills(data.from, "hanqing__xiandang")
    end
  end,
})

xiandang:addEffect(fk.TargetConfirmed, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(xiandang.name) and data.from ~= player and not data.use.extraUse
  end,
  on_refresh = function (self, event, target, player, data)
    data.use.extraUse = true
    data.from:addCardUseHistory(data.card.trueName, -1)
  end,
})

return xiandang
